﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace TestByWire.Test
{
    [TestClass]
    public class InteractionEqualityComparerTests
    {
        private InteractionEqualityComparer _target;
		private IContainerInteraction _instance1;
		private IContainerInteraction _instance2;

        [TestInitialize]
        public void Init()
        {
			_instance1 = MockRepository.GenerateStub<IContainerInteraction>();
			_instance2 = MockRepository.GenerateStub<IContainerInteraction>();
            _target=new InteractionEqualityComparer();
        }

        [TestMethod]
        public void Inheritance()
        {
            Assert.IsInstanceOfType(_target, typeof(IEqualityComparer<IContainerInteraction>));
        }

        [TestMethod]
        public void DoubleNull()
        {
            Assert.IsTrue(_target.Equals(null, null));
        }

        [TestMethod]
        public void FirstNull()
        {
            Assert.IsFalse(_target.Equals(null, _instance2));
        }

        [TestMethod]
        public void SecondNull()
        {
            Assert.IsFalse(_target.Equals(_instance1, null));
        }

        [TestMethod]
        public void TwoEmptyInstances()
        {
            Assert.IsTrue(_target.Equals(_instance1, _instance2));
        }


        [TestMethod]
        public void TypeSetOnFirst()
        {
            _instance1.Stub(x => x.RegistrationType).Return(typeof (String));

            Assert.IsFalse(_target.Equals(_instance1, _instance2));
        }


        [TestMethod]
        public void DifferentTypeSetOnInstances()
        {
            _instance1.Stub(x => x.RegistrationType).Return(typeof(String));
            _instance2.Stub(x => x.RegistrationType).Return(typeof(Int32));

            Assert.IsFalse(_target.Equals(_instance1, _instance2));
        }

        [TestMethod]
        public void SameTypeSetOnInstances()
        {
            _instance1.Stub(x => x.RegistrationType).Return(typeof(String));
            _instance2.Stub(x => x.RegistrationType).Return(typeof(String));

            Assert.IsTrue(_target.Equals(_instance1, _instance2));
        }

        [TestMethod]
        public void NameSetOnFirst()
        {
            _instance1.Stub(x => x.RegistrationName).Return("foo");

            Assert.IsFalse(_target.Equals(_instance1, _instance2));
        }

        [TestMethod]
        public void NameSetOnSecond()
        {
            _instance2.Stub(x => x.RegistrationName).Return("foo");

            Assert.IsFalse(_target.Equals(_instance1, _instance2));
        }

        [TestMethod]
        public void DifferentNameSetOnInstances()
        {
            _instance1.Stub(x => x.RegistrationName).Return("foo");
            _instance2.Stub(x => x.RegistrationName).Return("bar");

            Assert.IsFalse(_target.Equals(_instance1, _instance2));
        }

        [TestMethod]
        public void SameNameSetOnInstances()
        {
            _instance1.Stub(x => x.RegistrationName).Return("foo");
            _instance2.Stub(x => x.RegistrationName).Return("foo");

            Assert.IsTrue(_target.Equals(_instance1, _instance2));
        }
    }
}
